using System.ComponentModel;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;

namespace Microsoft.Practices.Repository.Configuration.Design
{
    /// <summary>
    /// Represents the design time node for a single <see cref="KeyValueConfigurationElement"/>, 
    /// inside the <see cref="RepositoryFactorySection"/>.
    /// </summary>
    [Image(typeof(RepositoryNode))]
    [SelectedImage(typeof(RepositoryNode))]
    public class RepositoryNode : ConfigurationNode
    {
        private string _interfaceType;
        private string _repositoryType;
        
        /// <summary>
        /// Initializes a new <see cref="RepositoryNode"/>.
        /// </summary>
        public RepositoryNode()
            : this(string.Empty, string.Empty)
        {
        }

        /// <summary>
        /// Initializes a new <see cref="RepositoryNode"/> with a specific key and value.
        /// </summary>
        /// <param name="interfaceType">The key for this <see cref="RepositoryNode"/>.</param>
        /// <param name="repositoryType">The value for this <see cref="RepositoryNode"/>.</param>
        public RepositoryNode(string interfaceType, string repositoryType) : base(GetName(repositoryType))
        {
            _interfaceType = interfaceType;
            _repositoryType = repositoryType;

        }

        private static string GetName(string repositoryType)
        {
            string[] theSplit = repositoryType.Split(',')[0].Split('.');
            return theSplit[theSplit.Length - 1];
        }

        /// <summary>
        /// Gets or sets the value for this setting.
        /// </summary>
        [Category("Category")]
        [Description("Description")]
        public string InterfaceType
        {
            get { return _interfaceType; }
            set { _interfaceType = value; }
        }

        /// <summary>
        /// Gets or sets the value for this setting.
        /// </summary>
        [Category("Category")]
        [Description("Description")]
        public string RepositoryType
        {
            get { return _repositoryType; }
            set { _repositoryType = value; }
        }
    }
}